package com.xuanmiao.smsback.service.platform.operator.impl;

import com.xuanmiao.smsback.domain.qo.OperatorInfoQO;
import com.panshi.hujin2.base.common.util.DozerUtils;
import com.panshi.hujin2.base.domain.page.Page;
import com.xuanmiao.smsback.dao.mapper.OperatorInfoMapper;
import com.xuanmiao.smsback.dao.model.OperatorInfoDO;

import com.xuanmiao.smsback.model.OperatorInfoBO;
import com.xuanmiao.smsback.service.platform.operator.OperatorInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class OperatorInfoServiceImpl implements OperatorInfoService {
    @Autowired
    private OperatorInfoMapper operatorInfoMapper;
    @Override
    public List<OperatorInfoBO> getList(OperatorInfoQO operatorInfoQO) {
        if(operatorInfoQO == null){
            operatorInfoQO = new OperatorInfoQO();
        }
        //获取运营商数量
        Integer count = operatorInfoMapper.count(operatorInfoQO);
        Page page = operatorInfoQO.getPage();
        //设置总记录数
        page.setTotalNumber(count);
        List<OperatorInfoDO> operatorInfoDO = operatorInfoMapper.queryOperatorInfo(operatorInfoQO);
        if(operatorInfoDO!=null && operatorInfoDO.size()>0){
            List<OperatorInfoBO> operatorInfoBO = DozerUtils.convertList(operatorInfoDO, OperatorInfoBO.class);

            return operatorInfoBO;
                    //DozerUtils.convertList(operatorInfoMapper.query(operatorInfoQO),OperatorInfoBO.class);
        }
        return Collections.emptyList();


    }

    @Override
    public OperatorInfoBO getById(Integer id) {
        return DozerUtils.convert(operatorInfoMapper.getById(id),OperatorInfoBO.class);
    }

    @Override
    public void update(OperatorInfoBO operatorInfoBO) {
        operatorInfoMapper.update(DozerUtils.convert(operatorInfoBO,OperatorInfoDO.class));

    }


}
